﻿Imports MeoTom.Core.BLL
Imports System.IO
Imports Microsoft.ApplicationBlocks.Data

Namespace DAL
    Public Class LinkCatProvider
        Inherits DataAccess
        Private util As New Utilities.Common()

        Public Sub New()

        End Sub

        Public Sub Create(ByVal lc As LinkCat)
            Try
                Dim param(3) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@CatName", SqlDbType.NVarChar, 50)
                param(0).Value = lc.CatName
                param(1) = New SqlClient.SqlParameter("@Description", SqlDbType.NVarChar, 450)
                param(1).Value = lc.Description
                param(2) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(2).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_LinkCat_Create", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Sub Update(ByVal lc As LinkCat)
            Try
                Dim param(4) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@CatID", SqlDbType.Int, 4)
                param(0).Value = lc.CatID
                param(1) = New SqlClient.SqlParameter("@CatName", SqlDbType.NVarChar, 50)
                param(1).Value = lc.CatName
                param(2) = New SqlClient.SqlParameter("@Description", SqlDbType.NVarChar, 450)
                param(2).Value = lc.Description
                param(3) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(3).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_LinkCat_Update", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Sub Delete(ByVal lc As LinkCat)
            Try
                Dim param(2) As SqlClient.SqlParameter
                param(0) = New SqlClient.SqlParameter("@CatID", SqlDbType.Int, 4)
                param(0).Value = lc.CatID
                param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
                param(1).Value = Configs.SiteID

                SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_LinkCat_Delete", param)
            Catch ex As Exception
                Throw New Exception(ex.Message)
            End Try
        End Sub

        Public Function GetByName(ByVal lc As LinkCat) As DataSet
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@CatName", SqlDbType.NVarChar, 50)
            param(0).Value = "%" & lc.CatName & "%"
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_LinkCat_GetByName", param)
        End Function

        Public Function GetAll() As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_LinkCat_GetAll", param)
        End Function

        Public Function GetByID(ByVal lc As LinkCat) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@CatID", SqlDbType.Int, 4)
            param(0).Value = lc.CatID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_LinkCat_GetByID", param)
        End Function
    End Class
End Namespace